<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Android,Note," />





  <link rel="alternate" href="/atom.xml" title="GrantonZhuang's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="接上文 Service 的启动过程 启动状态">
<meta property="og:type" content="article">
<meta property="og:title" content="Service 的启动过程 绑定状态">
<meta property="og:url" content="https://grantonzhuang.github.io/2016/08/10/SthAboutServiceLaunch2/index.html">
<meta property="og:site_name" content="GrantonZhuang's Blog">
<meta property="og:description" content="接上文 Service 的启动过程 启动状态">
<meta property="og:updated_time" content="2016-08-10T14:08:54.793Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Service 的启动过程 绑定状态">
<meta name="twitter:description" content="接上文 Service 的启动过程 启动状态">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="https://grantonzhuang.github.io/2016/08/10/SthAboutServiceLaunch2/"/>

  <title> Service 的启动过程 绑定状态 | GrantonZhuang's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">GrantonZhuang's Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle"></p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Service 的启动过程 绑定状态
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-08-10T22:04:24+08:00" content="2016-08-10">
              2016-08-10
            </time>
          </span>

          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>接上文 <a href="https://grantonzhuang.github.io/2016/08/07/SthAboutServiceLaunch/">Service 的启动过程 启动状态</a></p>
<a id="more"></a>
<h2 id="入口"><a href="#入口" class="headerlink" title="入口"></a>入口</h2><p>与 startService 类似，通过成员变量 mBase 的 bindService 方法，再调用 <code>bindServiceCommon()</code> 方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">boolean</span> <span class="title">bindServiceCommon</span><span class="params">(Intent service, ServiceConnection conn, <span class="keyword">int</span> flags,</span></span></div><div class="line">        UserHandle user) &#123;</div><div class="line">    <span class="comment">// 处理 ServiceConnection</span></div><div class="line">    IServiceConnection sd;</div><div class="line">    <span class="keyword">if</span> (conn == <span class="keyword">null</span>) &#123;</div><div class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> IllegalArgumentException(<span class="string">"connection is null"</span>);</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span> (mPackageInfo != <span class="keyword">null</span>) &#123;</div><div class="line">        sd = mPackageInfo.getServiceDispatcher(conn, getOuterContext(),</div><div class="line">                mMainThread.getHandler(), flags);</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"Not supported in system context"</span>);</div><div class="line">    &#125;</div><div class="line">    <span class="comment">// 交给 AMS 接管</span></div><div class="line">    <span class="keyword">int</span> res = ActivityManagerNative.getDefault().bindService(</div><div class="line">        mMainThread.getApplicationThread(), getActivityToken(), service,</div><div class="line">        service.resolveTypeIfNeeded(getContentResolver()),</div><div class="line">        sd, flags, getOpPackageName(), user.getIdentifier());</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="处理-ServiceConnection"><a href="#处理-ServiceConnection" class="headerlink" title="处理 ServiceConnection"></a>处理 ServiceConnection</h2><p>在 <code>bindServiceCommon()</code> 方法中，首先会将 <code>ServiceConnection</code> 转换成 <code>IServiceConnection</code> 对象，因为 Service 的绑定可以是进程内，也可以是进程间，所以 <code>ServiceConnection</code> 需要借助 Binder 才能让服务端回调自身的方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">final</span> IServiceConnection <span class="title">getServiceDispatcher</span><span class="params">(ServiceConnection c,</span></span></div><div class="line">        Context context, Handler handler, <span class="keyword">int</span> flags) &#123;</div><div class="line">    <span class="keyword">synchronized</span> (mServices) &#123;</div><div class="line">        LoadedApk.ServiceDispatcher sd = <span class="keyword">null</span>;`</div><div class="line">        ArrayMap&lt;ServiceConnection, LoadedApk.ServiceDispatcher&gt; map = mServices.get(context);</div><div class="line">        <span class="keyword">if</span> (map != <span class="keyword">null</span>) &#123;</div><div class="line">            sd = map.get(c);</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">if</span> (sd == <span class="keyword">null</span>) &#123;</div><div class="line">            sd = <span class="keyword">new</span> ServiceDispatcher(c, context, handler, flags);</div><div class="line">            <span class="keyword">if</span> (map == <span class="keyword">null</span>) &#123;</div><div class="line">                map = <span class="keyword">new</span> ArrayMap&lt;ServiceConnection, LoadedApk.ServiceDispatcher&gt;();</div><div class="line">                mServices.put(context, map);</div><div class="line">            &#125;</div><div class="line">            map.put(c, sd);</div><div class="line">        &#125; <span class="keyword">else</span> &#123;</div><div class="line">            sd.validate(context, handler);</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">return</span> sd.getIServiceConnection();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>这里的 mServices 是一个 HashMap 对象，以传入的 ServiceConnection 实例为 key, 缓存 <code>ServiceDispatcher</code> 对象。</p>
<p>这个 <code>ServiceDispatcher</code> 对象中存储 <code>InnerConnection</code> 和 <code>ServiceConnection</code> 对象。</p>
<h2 id="在-AMS-中的处理"><a href="#在-AMS-中的处理" class="headerlink" title="在 AMS 中的处理"></a>在 AMS 中的处理</h2><p>在 AMS 中, 同样会经过一系列的方法调用</p>
<blockquote>
<p>中间会和 startService() 方法一样，调用 ApplicationThread 的 <code>scheduleCreateService()</code> 方法进行 Service 的创建，但是会多出一个 <code>scheduleBindService()</code> 的处理。</p>
</blockquote>
<ul>
<li><code>ActivityManagerService#bindService()</code></li>
<li><code>ActiveServices#bindServiceLocked()</code></li>
<li><code>ActiveServices#bringUpServiceLocked()</code></li>
<li><code>ActiveServices#realStartServiceLocked()</code></li>
<li><code>ActiveServices#requestServiceBindingsLocked()</code></li>
<li><code>ActiveServices#requestServiceBindingLocked()</code></li>
<li><code>r.app.thread.scheduleBindService()</code></li>
</ul>
<h2 id="在-ApplicationThread-中的处理"><a href="#在-ApplicationThread-中的处理" class="headerlink" title="在 ApplicationThread 中的处理"></a>在 ApplicationThread 中的处理</h2><p>同样交给 Handler 的子类 H 处理</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title">scheduleBindService</span><span class="params">(IBinder token, Intent intent,</span></span></div><div class="line">        <span class="keyword">boolean</span> rebind, <span class="keyword">int</span> processState) &#123;</div><div class="line">    <span class="comment">// ...</span></div><div class="line">    sendMessage(H.BIND_SERVICE, s);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><code>H#handleMessage()</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">case</span> BIND_SERVICE:</div><div class="line">    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, <span class="string">"serviceBind"</span>);</div><div class="line">    handleBindService((BindServiceData)msg.obj);</div><div class="line">    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);</div><div class="line">    <span class="keyword">break</span>;</div></pre></td></tr></table></figure>
<p><code>ApplicationThread#handleBindService()</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">handleBindService</span><span class="params">(BindServiceData data)</span> </span>&#123;</div><div class="line">    <span class="comment">// ...</span></div><div class="line">    <span class="keyword">if</span> (!data.rebind) &#123;</div><div class="line">    <span class="comment">// 回调 Service 的 onBind 方法，这里返回的即为 IBinder 实例</span></div><div class="line">        IBinder binder = s.onBind(data.intent);</div><div class="line">        ActivityManagerNative.getDefault().publishService(</div><div class="line">                data.token, data.intent, binder);</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">        s.onRebind(data.intent);</div><div class="line">        ActivityManagerNative.getDefault().serviceDoneExecuting(</div><div class="line">                data.token, SERVICE_DONE_EXECUTING_ANON, <span class="number">0</span>, <span class="number">0</span>);</div><div class="line">    &#125;</div><div class="line">    <span class="comment">// ...</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>进行到这里，Service 的绑定已经完成了，但是其他工作还没有做完，在 <code>onBind()</code> 回调的后面，AMS 调用了一个 <code>publishService()</code> 方法。</p>
<h2 id="客户端的处理"><a href="#客户端的处理" class="headerlink" title="客户端的处理"></a>客户端的处理</h2><p>AMS 中的 <code>publishService()</code> 方法调用了 <code>ActiveServices#publishServiceLocked()</code></p>
<p>在这个方法里关键的一行是</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">c.conn.connected(r.name, service);</div></pre></td></tr></table></figure>
<p>这里的 conn 是一个 IServiceConnection 对象，就是在文章开头提到的 ServiceConnection 与之建立联系用以进程间通信的对象。</p>
<p>可以在 <code>ServiceDispatcher</code> 中找到 <code>IServiceConnection.Stub</code> 的实现, 其实就是 <code>InnerConnection</code>.</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">InnerConnection</span> <span class="keyword">extends</span> <span class="title">IServiceConnection</span>.<span class="title">Stub</span> </span>&#123;</div><div class="line">    <span class="keyword">final</span> WeakReference&lt;LoadedApk.ServiceDispatcher&gt; mDispatcher;</div><div class="line"></div><div class="line">    InnerConnection(LoadedApk.ServiceDispatcher sd) &#123;</div><div class="line">        mDispatcher = <span class="keyword">new</span> WeakReference&lt;LoadedApk.ServiceDispatcher&gt;(sd);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">connected</span><span class="params">(ComponentName name, IBinder service)</span> <span class="keyword">throws</span> RemoteException </span>&#123;</div><div class="line">        LoadedApk.ServiceDispatcher sd = mDispatcher.get();</div><div class="line">        <span class="keyword">if</span> (sd != <span class="keyword">null</span>) &#123;</div><div class="line">            sd.connected(name, service);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><code>ServiceDispatcher#connect()</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">connected</span><span class="params">(ComponentName name, IBinder service)</span> </span>&#123;</div><div class="line">    <span class="keyword">if</span> (mActivityThread != <span class="keyword">null</span>) &#123;</div><div class="line">        mActivityThread.post(<span class="keyword">new</span> RunConnection(name, service, <span class="number">0</span>));</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">        doConnected(name, service);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>这里 <code>mActivityThread</code> 是一个 Handler 对象，这个对象 post 了一个 Runnable.</p>
<p>这个 Runnable 的 run 方法如下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">private</span> <span class="keyword">final</span> <span class="class"><span class="keyword">class</span> <span class="title">RunConnection</span> <span class="keyword">implements</span> <span class="title">Runnable</span> </span>&#123;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</div><div class="line">        <span class="keyword">if</span> (mCommand == <span class="number">0</span>) &#123;</div><div class="line">            doConnected(mName, mService);</div><div class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (mCommand == <span class="number">1</span>) &#123;</div><div class="line">            doDeath(mName, mService);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>由于构造函数里 mCommand 为零，所以执行的是 <code>doConnected()</code> 方法，在这个方法里回调了 <code>ServiceConnection</code> 的 <code>onServiceConnected()</code> 方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">doConnected</span><span class="params">(ComponentName name, IBinder service)</span> </span>&#123;</div><div class="line">    <span class="comment">// ...</span></div><div class="line">    <span class="comment">// If there was an old service, it is not disconnected.</span></div><div class="line">    <span class="keyword">if</span> (old != <span class="keyword">null</span>) &#123;</div><div class="line">        mConnection.onServiceDisconnected(name);</div><div class="line">    &#125;</div><div class="line">    <span class="comment">// If there is a new service, it is now connected.</span></div><div class="line">    <span class="keyword">if</span> (service != <span class="keyword">null</span>) &#123;</div><div class="line">        mConnection.onServiceConnected(name, service);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>end.</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag">#Android</a>
          
            <a href="/tags/Note/" rel="tag">#Note</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/08/07/SthAboutServiceLaunch/" rel="next" title="Service 的启动过程 启动状态">
                <i class="fa fa-chevron-left"></i> Service 的启动过程 启动状态
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/09/02/BroadcastReceiverWorkProcess/" rel="prev" title="BroadcastReceiver 的工作过程">
                BroadcastReceiver 的工作过程 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://ww1.sinaimg.cn/mw690/6e8939a6gw1f3g1u1mc6lj20hs0hsmxf.jpg"
               alt="Granton Zhuang" />
          <p class="site-author-name" itemprop="name">Granton Zhuang</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives/index.html">
              <span class="site-state-item-count">26</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#入口"><span class="nav-number">1.</span> <span class="nav-text">入口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#处理-ServiceConnection"><span class="nav-number">2.</span> <span class="nav-text">处理 ServiceConnection</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#在-AMS-中的处理"><span class="nav-number">3.</span> <span class="nav-text">在 AMS 中的处理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#在-ApplicationThread-中的处理"><span class="nav-number">4.</span> <span class="nav-text">在 ApplicationThread 中的处理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#客户端的处理"><span class="nav-number">5.</span> <span class="nav-text">客户端的处理</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Granton Zhuang</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  

  

  

</body>
</html>
